package com.huadao.cart_ccs.experiment.confirmBeforeCulture.produceInfo;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.huadao.cart_ccs.R;
import com.huadao.cart_ccs.base.BaseFragment;
import com.huadao.cart_ccs.base.BasePresenter;
import com.huadao.cart_ccs.common.TimeUtil;
import com.huadao.cart_ccs.common.dialog.DialogFragmentHelper;
import com.huadao.cart_ccs.common.dialog.IDialogResultListener;
import com.huadao.cart_ccs.data.bean.Project;
import com.huadao.cart_ccs.main.CartApplication;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ProduceInfoFrag extends BaseFragment {

    @BindView(R.id.tv_UniqueIdentificationCode)
    TextView tv_UniqueIdentificationCode;
    @BindView(R.id.tv_projectName)
    TextView tv_projectName;
    @BindView(R.id.tv_bodyWeight)
    TextView tv_bodyWeight;
    @BindView(R.id.tv_name)
    TextView tv_name;
    @BindView(R.id.tv_specification)
    TextView tv_specification;
    @BindView(R.id.tv_sourceCode)
    TextView tv_sourceCode;
    @BindView(R.id.tv_exceptedProduction)
    TextView tv_exceptedProduction;
    @BindView(R.id.tv_producePurpose)
    TextView tv_producePurpose;
    @BindView(R.id.tv_ClinicalProgramNumber)
    TextView tv_ClinicalProgramNumber;
    @BindView(R.id.tv_produceLifeCycle)
    TextView tv_produceLifeCycle;
    @BindView(R.id.tv_produceEvidence)
    TextView tv_produceEvidence;
    @BindView(R.id.tv_receiveEvidence)
    TextView tv_receiveEvidence;
    @BindView(R.id.tv_note)
    TextView tv_note;
    @BindView(R.id.tv_produceOperator)
    TextView tv_produceOperator;
    @BindView(R.id.tv_produceOperatorSupervise)
    TextView tv_produceOperatorSupervise;
    @BindView(R.id.tv_produceTaskGetTime)
    TextView tv_produceTaskGetTime;

    @OnClick(R.id.btn_confirm)
    public void onViewClicked() {
        DialogFragmentHelper.showConfirmDialog(getContext(), "", "确认无误，是否进入物料确认阶段？", new IDialogResultListener<Integer>() {
            @Override
            public void onDataResult(Integer result) {
                if(result==DialogInterface.BUTTON_POSITIVE){
                    if(confirmProduceInfo!=null){
                        confirmProduceInfo.onConfirmProduceInfo();
                    }
                }
            }
        },true);
    }

    public interface ConfirmProduceInfo {
        void onConfirmProduceInfo();
    }

    private ConfirmProduceInfo confirmProduceInfo;

    @Override
    public int getContentViewId() {
        return R.layout.frag_produce_info;
    }

    @Override
    protected void initAllMembersView(Bundle savedInstanceState) {
        Project project=CartApplication.getInstance().getSystemProject();
        if(project==null){
            return;
        }
        tv_UniqueIdentificationCode.setText(project.getIdentifier());
        tv_projectName.setText(project.getProjectName());
        tv_bodyWeight.setText(String.valueOf(project.getWeight()));
        tv_name.setText(project.getProductName());
        tv_specification.setText(project.getSpecification());
        tv_sourceCode.setText(project.getIdentifier());
        tv_exceptedProduction.setText(project.getExpectedOutput());
        tv_producePurpose.setText(project.getProdUse());
        tv_ClinicalProgramNumber.setText(project.getPlanCode());
        StringBuilder stringBuilder=new StringBuilder();
        if(project.getProdCycleStartTime()!=null) {
            stringBuilder.append(TimeUtil.date_sdf.format(project.getProdCycleStartTime()));
        }
        stringBuilder.append(" 至 ");
        if(project.getProdCycleEndTime()!=null) {
            stringBuilder.append(TimeUtil.date_sdf.format(project.getProdCycleEndTime()));
        }
        tv_produceLifeCycle.setText(stringBuilder);
        tv_produceEvidence.setText(project.getProdAccordingTo());
        tv_receiveEvidence.setText(project.getAcceptAccordingTo());
        tv_note.setText(project.getRemark());
        tv_produceOperator.setText(project.getProdUser1Name());
        tv_produceOperatorSupervise.setText(project.getProdUser2Name());
        if(project.getCreatedTime()!=null) {
            tv_produceTaskGetTime.setText(TimeUtil.log_sdf.format(project.getCreatedTime()));
        }
    }

    @Override
    protected BasePresenter getPresenter() {
        return null;
    }

    public void setConfirmProduceInfo(ConfirmProduceInfo confirmProduceInfo) {
        this.confirmProduceInfo = confirmProduceInfo;
    }
}
